#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

ll p, b, n;

ll fastpow(ll b, ll p, ll mod) {
  ll res = 1;
  while (p) {
    if (p & 1) res = res * b % mod;
    b = b * b % mod;
    p >>= 1;
  }
  return res;
}
ll bsgs(ll p, ll b, ll n) {
  map<ll, ll> mpa;
  ll k = sqrt(p) + 1;
  ll x = 1;
  rep(i, 0, k - 1) {
    mpa[x] = i;
    if (x == n) return i;  // 特殊处理
    x = x * b % p;
  }
  b = fastpow(x, p - 2, p), x = 1;
  rep(i, 0, k - 1) {
    ll y = x * n % p;
    if (mpa.count(y)) {
      return i * k + mpa[y];
    }
    x = x * b % p;
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> p >> b >> n;
  ll ans = bsgs(p, b, n);
  if (ans == -1)
    cout << "no solution";
  else
    cout << ans;
  return 0;
}